package com.panshi.controller.audit;

import com.panshi.api.ArticleauditApi;
import com.panshi.pagevo.PageBeanVo;
import com.panshi.po.ArticleauditPo;
import com.panshi.vo.ArticleauditLikeQueryVo;
import com.panshi.vo.ArticleauditStateQueryVo;
import com.panshi.vo.PageModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 文章审核
 */
@Controller
@Slf4j
public class AuditController {

    @Autowired
    private ArticleauditApi articleauditApi;

    /**
     * 跳转页面
     * @return
     */
    @GetMapping("queryAudit")
    public  String query(){

        return "audit/audit-query";
    }

    /**
     * 查询全部
     * @param ps
     * @return
     */
    @PostMapping("audit-queryall")
    @ResponseBody
    public PageModel<ArticleauditPo>  queryall(PageModel<ArticleauditPo> ps){

        ps.init();
        PageBeanVo pageBeanVo=new PageBeanVo();
        pageBeanVo.setCurrentPage(ps.getCurrentPage());
        pageBeanVo.setPageSize(ps.getPageSize());

        log.info("pageBeanVo============{}",pageBeanVo);
        List<ArticleauditPo> list=  articleauditApi.query(pageBeanVo).getData();
        Integer integer=articleauditApi.articleAuditCount().getData();
        log.info("listArticleauditPo==========={}",list);
        ps.setList(list);
        ps.setCount(integer);
      return ps;
    }


    /**
     * 根据审核表标题模糊查询
     * @param ps
     * @param title
     * @return
     */
    @PostMapping("audit-queryDim/{title}")
    @ResponseBody
    public   PageModel<ArticleauditPo>  queryDim(PageModel<ArticleauditPo> ps, @PathVariable String title){
        log.info("title====={}",title);
        ps.init();
        ArticleauditLikeQueryVo articleauditLikeQueryVo=new ArticleauditLikeQueryVo();
        articleauditLikeQueryVo.setTitle(title);
        articleauditLikeQueryVo.setCurrentPage(ps.getCurrentPage());
        articleauditLikeQueryVo.setPageSize(ps.getPageSize());
       List<ArticleauditPo> list=articleauditApi.likeQuery(articleauditLikeQueryVo).getData();
        Integer integer= articleauditApi.titleCount(title).getData();
       log.info("listqueryDim======={}",list);
       ps.setList(list);
        ps.setCount(integer);
       return ps;
    }


    /**
     * 根据审核表状态查询
     * @param ps
     * @param state
     * @return
     */
    @PostMapping("audit-queryState/{state}")
    @ResponseBody
    public PageModel<ArticleauditPo>  queryState(PageModel<ArticleauditPo> ps,@PathVariable Integer state){
        log.info("state============{}",state);

        ps.init();
        ArticleauditStateQueryVo articleauditStateQueryVo=new ArticleauditStateQueryVo();
        articleauditStateQueryVo.setState(state);
        articleauditStateQueryVo.setCurrentPage(ps.getCurrentPage());
        articleauditStateQueryVo.setPageSize(ps.getPageSize());
      List<ArticleauditPo>  list=articleauditApi.stateQuery(articleauditStateQueryVo).getData();
        Integer integer=   articleauditApi.stateCount(state).getData();
        log.info("listqueryState============={}",list);
        ps.setList(list);
        ps.setCount(integer);
        return ps;
    }


}
